package org.bozo.im.service.protocols.xmpp.stanza.processor.bind;

import java.io.IOException;

import org.bozo.im.service.Constants;
import org.bozo.im.service.protocols.xmpp.XMPPSession;
import org.bozo.im.service.protocols.xmpp.stanza.Stanza;
import org.bozo.im.service.protocols.xmpp.stanza.processor.StanzaProcessor;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.util.Log;

public class JidStanzaProcessor extends StanzaProcessor {

	
	private static JidStanzaProcessor mInstance;
	
	private JidStanzaProcessor() {}
	
	public static JidStanzaProcessor getInstance() {
		if (mInstance == null)
			mInstance = new JidStanzaProcessor();
		return mInstance;
	}
	
	@Override
	public Stanza getStanza() {
		return Stanza.BIND_JID;
	}

	@Override
	public void processStanza(XmlPullParser pParser, XMPPSession pSession, StanzaProcessor pParentProcessor) throws XmlPullParserException, IOException {

		if (pParentProcessor == BindStanzaProcessor.getInstance()) {
			
			String lNewJid = pParser.nextText();
			
			// ---------------------------------------------------------------------------------------
			Log.d(Constants.ACTIVITY_TAG, "org.bozo.im.xmpp.stanza.processor.bind.JidStanzaProcessor.processStanza ---------- Changing JID to: " + lNewJid);
			// ---------------------------------------------------------------------------------------
			
			pSession.getConfiguration().getLoginJID().update(lNewJid);
		}
	}
}
